package com.zz.Map.Map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class Test2 {
    public static void main(String args[]){
        //准备一个Map集合
        Map<String, Double> map = new HashMap<>();
        map.put("牛魔王", 187.4);
        map.put("铁扇公主", 170.4);
        map.put("孙悟空", 156.7);
        map.put("唐僧", 179.4);
        System.out.println(map);
        //获取所有键
        Set<String> keys = map.keySet();
        System.out.println(keys);
        //根据键获取对应值
        for(String key : keys){
            double value = map.get(key);
            System.out.println(key + "=>" + value);
        }

        //2.调用Map集合提供entrySet方法，把Map集合转换成键值对类型的Set集合
        Set<Map.Entry<String, Double>> entries = map.entrySet();
        for(Map.Entry<String, Double> entry : entries){
            String key = entry.getKey();
            double value = entry.getValue();
            System.out.println(key + "=>" + value);
        }

        //方式三Lambda遍历
        map.forEach((k, v)->{
            System.out.println(k + "->" + v);
        });

//        map.forEach(new BiConsumer <String, Double>() {
//            @Override
//            public void accept(String k, Double v) {
//                System.out.println(k + "=>" + v);
//            }
//        });
    }
}
